package com.killer.edu.boss.controller;

import com.killer.edu.boss.entity.form.CourseForm;
import com.killer.edu.common.result.ResponseDTO;
import com.killer.edu.common.util.ConverUtil;
import com.killer.edu.course.api.CourseRemoteService;
import com.killer.edu.course.api.dto.CourseDTO;
import com.killer.edu.course.api.param.CourseQueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseRemoteService courseRemoteService;

    /**
     * 保存或更新课程信息
     * @param courseForm
     * @return
     */
    @PostMapping("/saveOrUpdateCourse")
    @ResponseBody
    public ResponseDTO saveOrUpdateCourse(@RequestBody CourseForm courseForm){
        CourseDTO courseDTO = ConverUtil.convert(courseForm, CourseDTO.class);
        courseRemoteService.saveOrUpdateCourse(courseDTO);
        return ResponseDTO.success(courseDTO);
    }

    /**
     * 根据id获取课程信息
     * @param courseId
     * @return
     */
    @GetMapping("/getCourseById")
    @ResponseBody
    public ResponseDTO getCourseById(@RequestParam("courseId") Integer courseId)  {
        CourseDTO courseDTO = courseRemoteService.getCourseById(courseId);
        return ResponseDTO.success(courseDTO);
    }
    /**
     *  课程上下架
     */
    @PostMapping("/changeState")
    @ResponseBody
    public ResponseDTO changeState(@RequestParam("courseId") Integer courseId,
                                   @RequestParam("status") Integer status)  {
        Boolean flag = courseRemoteService.changeState(courseId, status);
        return ResponseDTO.success(flag);
    }

    @PostMapping("/getQueryCourses")
    @ResponseBody
    public ResponseDTO getQueryCourses(@RequestBody CourseQueryParam courseQueryParam)  {
        return null;
    }



}
